﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Job.Web.Framework;
using Job.Logic.Personal;
using Job.Entity;

namespace Job.Web.userControls.Personal
{
    public partial class CareerObjective : BaseCtrl
    {
        int personalid = myR["resumeid"].IntValue;
        PersonalLogic pl = new PersonalLogic();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.LoadData();
            }
        }

        private void LoadData()
        {
            try
            {
                JobPersonInfo info = pl.GetSinglePersonBaseInfo(personalid);
                if (info != null)
                {
                    txtHopeAddress.Text = info.HopeAddr;
                    txtHopeIndustry.Text = info.HopeIndustry;
                    txtHopePosition.Text = info.HopePosition;

                    //求职类型
                    string applystyle = string.Empty;
                    if (info.ApplyStyle.HasValue)
                        applystyle = info.ApplyStyle.Value.ToString();
                    WebCommon.SetDropDownFromDict(ddlApplyStyle, applystyle, Constants.GetDictionaryCode(Constants.DictionaryType.APPLY_TYPE), true);

                    //期望薪资
                    string salaryLevel = string.Empty;
                    if (info.HopeSalary.HasValue)
                        salaryLevel = info.HopeSalary.Value.ToString();
                    WebCommon.SetDropDownFromDict(ddlMoney, salaryLevel, Constants.GetDictionaryCode(Constants.DictionaryType.SALARY_LEVEL), false);

                    string avDay = info.AvailabilityDay.ToString();
                    WebCommon.SetDropDownFromDict(ddlDay, avDay, Constants.GetDictionaryCode(Constants.DictionaryType.PARTICIPATE_LEN), false);

                    //行业
                    WebCommon.LoadLevelDropDownList(ddlindustry1, ddlindustry11, IndustryRlist, Constants.GetParentCodeBySubCode(info.CurIndustry), info.CurIndustry, Constants.DictionaryType.INDUSTRY_CLASS);

                }

                txtSelf.Text = pl.GetPersonDesc(personalid);
            }

            catch (Exception ex)
            {

                ShowMessage("查询失败：<br>" + ex.Message);
                Logger.WriteLog("求职意向查询失败：" + ex.Message);
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {

                JobPersonInfo info = pl.GetSinglePersonBaseInfo(personalid);
                if (info != null)
                {
                    info.HopeAddr = txtHopeAddress.Text.Trim();
                    info.HopeIndustry = txtHopeIndustry.Text.Trim();
                    info.HopePosition = txtHopePosition.Text.Trim();
                    info.CurIndustry = ddlindustry11.SelectedValue.Trim();
                    info.ApplyStyle = Convert.ToInt32(ddlApplyStyle.SelectedValue.Trim());
                    info.HopeSalary = Convert.ToInt32(ddlMoney.SelectedValue.Trim());
                    info.AvailabilityDay = Convert.ToInt32(ddlDay.SelectedValue.Trim());
                    pl.UpdateCareerObjective(info);
                }

                pl.SavePersonDesc(personalid, txtSelf.Text.Trim());
            }
            catch (Exception ex)
            {

                ShowMessage("保存失败：<br>" + ex.Message);
                Logger.WriteLog("求职意向保存失败：" + ex.Message);
            }
        }

        private void ShowMessage(string message)
        {
            this.message.InnerHtml = "<font color=red>" + message + "</font>";
            this.message.Visible = true;
            this.message.Height = "30px";
            this.message.VAlign = "middle";
        }

    }
}